package com.itlong.cloud.controller.property;

import com.itlong.cloud.POJO.DTO.property.*;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectBuildInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectBuildSimpleInfoExVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectBuildSimpleInfoVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.PropertyErrorCodeEnum;
import com.itlong.cloud.equip.property.IPropertyEquipServiceClient;
import com.itlong.cloud.project.property.IPropertyBuildInfoServiceClient;
import com.itlong.cloud.project.property.IPropertyRoomInfoServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.words.NumberHandlerUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      楼栋信息管理控制器
 * </desc>
 *
 * @createDate 2017-09-21
 */
@RestController
@RequestMapping("project/buildInfo")
public class PropertyBuildInfoController extends BaseController {


    private final IPropertyBuildInfoServiceClient iPropertyBuildInfoServiceClient;   //楼栋信息服务接口协议提供对象.


    private final IPropertyRoomInfoServiceClient iPropertyRoomInfoServiceClient; //房屋信息服务器接口协议提供对象


    private final IPropertyEquipServiceClient iPropertyEquipServiceClient; //设备信息接口协议提供对象

    @Autowired
    public PropertyBuildInfoController(IPropertyBuildInfoServiceClient iPropertyBuildInfoServiceClient,
                                       IPropertyRoomInfoServiceClient iPropertyRoomInfoServiceClient,
                                       IPropertyEquipServiceClient iPropertyEquipServiceClient) {
        this.iPropertyBuildInfoServiceClient = iPropertyBuildInfoServiceClient;
        this.iPropertyRoomInfoServiceClient = iPropertyRoomInfoServiceClient;
        this.iPropertyEquipServiceClient = iPropertyEquipServiceClient;
    }

    /**
     * <desc>
     *      保存单个楼栋信息(含批量添加单元)
     * </desc>
     *
     * @param propertyProjectSaveBuildInfoDTO 添加楼栋信息数据传输对象
     * @return MessageVO 标准格式化响应结果
     * @author LouisLewis
     * @createDate 2017-09-19
     */
    @LoggerInfo(operateDesc = LogDescConstant.SAVE_BUILDINFO_LOG_DESC)
    @RequestMapping(path = "/save", method = RequestMethod.POST)
    @ResponseBody
    @AuthAccessRequired
//    @HystrixCommand(fallbackMethod = "saveBuildInfoFallbackMethod")
    public Object saveBuildInfo(PropertyProjectSaveBuildInfoDTO propertyProjectSaveBuildInfoDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyProjectSaveBuildInfoDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyProjectSaveBuildInfoDTO.class, request);

            //判断参数合法性
            if (null == propertyProjectSaveBuildInfoDTO) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }

            //项目编号不能为空
            if (StringUtils.isBlank(propertyProjectSaveBuildInfoDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }

            //楼栋名称不能为空
            if (StringUtils.isBlank(propertyProjectSaveBuildInfoDTO.getBuildName())) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NAME_EMPTY_ERR.getErrorCode());
            }

            //楼栋名称过长
            if (propertyProjectSaveBuildInfoDTO.getBuildName().length() > PlatformConstants.MAX_BUILD_NAME_LENGTH ){
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NAME_LENGTH_ERR.getErrorCode());
            }

            String buildNum = propertyProjectSaveBuildInfoDTO.getBuildNum();
            // 楼栋编号不能为空
            if (StringUtils.isBlank(buildNum)){
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NUM_EMPTY_ERR.getErrorCode());
            }
            // 判断楼栋编号的合法性
            int intBuildNum = StringHandlerUtil.strToIntDef(buildNum, 0);
            if (!NumberHandlerUtil.isInRange(intBuildNum,PlatformConstants.MIN_BUILD_NUM,PlatformConstants.MAX_BUILD_NUM)){
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NUM_INVALID_ERR.getErrorCode());
            }
            // 同一项目下楼栋编号唯一
            buildNum = NumberHandlerUtil.numFormatToString(intBuildNum, 3);
            PropertyProjectGetBuildInfoDTO propertyProjectGetBuildInfoDTO = new PropertyProjectGetBuildInfoDTO();
            propertyProjectGetBuildInfoDTO.setProjectId(propertyProjectSaveBuildInfoDTO.getProjectId());
            propertyProjectGetBuildInfoDTO.setBuildNum(buildNum);
            PropertyProjectBuildInfoVO oneBuildInfo = iPropertyBuildInfoServiceClient.getOneBuildInfo(propertyProjectGetBuildInfoDTO);
            if (oneBuildInfo != null){
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NUM_EXIST_ERR.getErrorCode());
            }
            propertyProjectSaveBuildInfoDTO.setBuildNum(buildNum);

            //备注名称过长
            if (!StringUtils.isEmpty(propertyProjectSaveBuildInfoDTO.getRemark())
                    && propertyProjectSaveBuildInfoDTO.getRemark().length() > PlatformConstants.MAX_BUILD_REMARK_LENGTH) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_REMARK_LENGTH_ERR.getErrorCode());
            }

            //单个楼栋下的单元数不允许超出限制(9个)
            if (!NumberHandlerUtil.isInRange(propertyProjectSaveBuildInfoDTO.getUnitCount(),
                    0, PlatformConstants.MAX_UNIT_NUM)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_UNITS_COUNT_ERR.getErrorCode());
            }

            //地面楼层范围1~99
            if (!NumberHandlerUtil.isInRange(propertyProjectSaveBuildInfoDTO.getGroundFloorNum(),
                    1, PlatformConstants.MAX_FLOOR_NUM)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_GROUND_FLOOR_NUM_ERR.getErrorCode());
            }

            //地下楼层范围0~98
            if (!NumberHandlerUtil.isInRange(propertyProjectSaveBuildInfoDTO.getUndergroundFloorNum(),
                    0, PlatformConstants.MAX_FLOOR_NUM - 1)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_UNDERGROUND_FLOOR_NUM_ERR.getErrorCode());
            }

            //总楼层数范围1~99
            int floorNum = propertyProjectSaveBuildInfoDTO.getUndergroundFloorNum() + propertyProjectSaveBuildInfoDTO.getGroundFloorNum();
            if (!NumberHandlerUtil.isInRange(floorNum,
                    1, PlatformConstants.MAX_FLOOR_NUM)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_FLOOR_NUM_ERR.getErrorCode());
            }

            //楼栋名称项目内重复
            if (null != getBuildInfoByBuildName(propertyProjectSaveBuildInfoDTO.getBuildName(), propertyProjectSaveBuildInfoDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NAME_REPEAT_ERR.getErrorCode());
            }

            //保存楼栋信息
            iPropertyBuildInfoServiceClient.saveBuildInfo(propertyProjectSaveBuildInfoDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());


        } catch (Exception e) {
            throw new DataAccessException("【物业-项目-楼栋信息】保存楼栋信息失败", e);
        }
    }

    /**
     * <desc>
     *      (熔断方法)保存单个楼栋信息(含批量添加单元)
     * </desc>
     *
     * @param propertyProjectSaveBuildInfoDTO 添加楼栋信息数据传输对象
     * @return MessageVO 标准格式化响应结果
     * @author LouisLewis
     * @createDate 2017-09-19
     */
    private MessageVO saveBuildInfoFallbackMethod(PropertyProjectSaveBuildInfoDTO propertyProjectSaveBuildInfoDTO) {
        return  new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
    }


    /**
     * <desc>
     *     获取指定项目的最小可用楼栋编号buildNum
     * </desc>
     *
     * @param projectId 项目id
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/05/29
     */
    @PostMapping(path = "/getMinAvailableBuildNum")
    @ResponseBody
    public Object getMinAvailableBuildNumByProjectId(String projectId){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            // 项目id不能为空
            if (StringUtils.isBlank(projectId)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            String buildNum = iPropertyBuildInfoServiceClient.getMinAvaliableBuildNumByProjectId(projectId);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),(Object)buildNum);
        } catch (Exception e) {
            throw new DataAccessException("【物业-项目-楼栋信息】获取指定项目最小可用楼栋编号失败", e);
        }
    }

    /**
     * <desc>
     *      修改楼栋信息【根据楼栋Id（BuildId）】
     * </desc>
     *
     * @param propertyProjectUpdateBuildInfoDTO 修改楼栋信息数据传输对象
     * @return MessageVO 标准格式化响应结果
     * @author LouisLewis
     * @createDate 2017-09-26
     */
    @LoggerInfo(operateDesc = LogDescConstant.UPDATE_BUILDINFO_LOG_DESC)
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    @ResponseBody
    @AuthAccessRequired
    public Object updateBuildInfo(PropertyProjectUpdateBuildInfoDTO propertyProjectUpdateBuildInfoDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyProjectUpdateBuildInfoDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyProjectUpdateBuildInfoDTO.class, request);
            //判断参数合法性
            if (null == propertyProjectUpdateBuildInfoDTO) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }

            //项目编号不能为空
            if (StringUtils.isBlank(propertyProjectUpdateBuildInfoDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            //楼栋ID不能为空
            if (StringUtils.isBlank(propertyProjectUpdateBuildInfoDTO.getBuildId())) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_ID_EMPTY_ERR.getErrorCode());
            }

            //备注名称过长
            if (!StringUtils.isEmpty(propertyProjectUpdateBuildInfoDTO.getRemark())
                    && propertyProjectUpdateBuildInfoDTO.getRemark().length() > PlatformConstants.MAX_BUILD_REMARK_LENGTH) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_REMARK_LENGTH_ERR.getErrorCode());
            }

            //楼栋信息是否仍然存在（可能已被其它地方删除），不存在则不允许更新
            PropertyProjectGetBuildInfoDTO propertyProjectGetBuildInfoDTO = new PropertyProjectGetBuildInfoDTO();
            propertyProjectGetBuildInfoDTO.setBuildId(propertyProjectUpdateBuildInfoDTO.getBuildId());
            PropertyProjectBuildInfoVO oldPropertyProjectBuildInfoVO = iPropertyBuildInfoServiceClient.getOneBuildInfo(propertyProjectGetBuildInfoDTO);
            if (oldPropertyProjectBuildInfoVO == null) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_INFO_NOT_EXISTS_ERR.getErrorCode());
            }

            //如需更新楼栋名称，则需对单元名称进行合法性检测
            String newBuildName = propertyProjectUpdateBuildInfoDTO.getBuildName();
            if (newBuildName != null) {
                //楼栋名称不能为空
                if (StringUtils.isBlank(newBuildName)){
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NAME_EMPTY_ERR.getErrorCode());
                }

                //楼栋名称过长
                if (newBuildName.length() > PlatformConstants.MAX_BUILD_NAME_LENGTH ){
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NAME_LENGTH_ERR.getErrorCode());
                }

                //若楼栋名称出现变更，则检查新名称是否被占用
                if (!StringHandlerUtil.compareStrWithOutEmpty(oldPropertyProjectBuildInfoVO.getBuildName(), newBuildName)
                        && null != getBuildInfoByBuildName(newBuildName, propertyProjectUpdateBuildInfoDTO.getProjectId())) {
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_NAME_REPEAT_ERR.getErrorCode());
                }
            }


            //如果尝试更新地面楼层或地下楼层，则需保证楼层参数合法，且该楼栋下无房间
            if (((propertyProjectUpdateBuildInfoDTO.getGroundFloorNum() != null)
                    && (!propertyProjectUpdateBuildInfoDTO.getGroundFloorNum().equals(oldPropertyProjectBuildInfoVO.getGroundFloorNum())))
                    ||
                    ((propertyProjectUpdateBuildInfoDTO.getUndergroundFloorNum() != null)
                  && (!propertyProjectUpdateBuildInfoDTO.getUndergroundFloorNum().equals(oldPropertyProjectBuildInfoVO.getUndergroundFloorNum())))) {

                int groundFloorNum = propertyProjectUpdateBuildInfoDTO.getGroundFloorNum() == null
                        ? oldPropertyProjectBuildInfoVO.getGroundFloorNum() : propertyProjectUpdateBuildInfoDTO.getGroundFloorNum();
                int undergroundFloorNum = propertyProjectUpdateBuildInfoDTO.getUndergroundFloorNum() == null
                        ? oldPropertyProjectBuildInfoVO.getUndergroundFloorNum() : propertyProjectUpdateBuildInfoDTO.getUndergroundFloorNum();
                //地面楼层范围1~99
                if (!NumberHandlerUtil.isInRange(groundFloorNum,
                        1, PlatformConstants.MAX_FLOOR_NUM)) {
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_GROUND_FLOOR_NUM_ERR.getErrorCode());
                }

                //地下楼层范围0~98
                if (!NumberHandlerUtil.isInRange(undergroundFloorNum,
                        0, PlatformConstants.MAX_FLOOR_NUM - 1)) {
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_UNDERGROUND_FLOOR_NUM_ERR.getErrorCode());
                }

                //总楼层数范围1~99
                int floorNum = undergroundFloorNum + groundFloorNum;
                if (!NumberHandlerUtil.isInRange(floorNum,
                        1, PlatformConstants.MAX_FLOOR_NUM)) {
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_FLOOR_NUM_ERR.getErrorCode());
                }

                //楼栋下存在房间，不允许修改地面楼层数或地下楼层数
                if (checkHasRoomInBuild(propertyProjectUpdateBuildInfoDTO.getBuildId())) {
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_HAS_ROOM_UPDATE_ERR.getErrorCode());
                }
                propertyProjectUpdateBuildInfoDTO.setGroundFloorNum(groundFloorNum);
                propertyProjectUpdateBuildInfoDTO.setUndergroundFloorNum(undergroundFloorNum);
            }


            //修改楼栋信息
            iPropertyBuildInfoServiceClient.updateBuildInfo(propertyProjectUpdateBuildInfoDTO);
            return new MessageVO(propertyProjectUpdateBuildInfoDTO.getBuildId(),BaseErrorCodeEnum.SUCCESS.getErrorCode());


        } catch (Exception e) {
            throw new DataAccessException("【物业_项目_楼栋信息】修改楼栋信息失败", e);
        }
    }

    /**
     * <desc>
     *      逻辑删除楼栋信息【根据楼栋Id（BuildId）】
     * </desc>
     *
     * @param buildId 待删除的楼栋Id
     * @return MessageVO 标准格式化响应结果
     * @author LouisLewis
     * @createDate 2017-09-26
     */
    @LoggerInfo(operateDesc = LogDescConstant.DELETE_BUILDINFO_LOG_DESC)
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    @ResponseBody
    @AuthAccessRequired
    public Object removeBuildInfo(String buildId) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            buildId = request.getAttribute("buildId") == null ? null : request.getAttribute("buildId").toString();
            //判断参数合法性
            if ((StringUtils.isBlank(buildId))) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_ID_EMPTY_ERR.getErrorCode());
            }

            //楼栋下存在房间，不允许删除
            if (checkHasRoomInBuild(buildId)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_HAS_ROOM_DELETE_ERR.getErrorCode());
            }


            //首先调用设备服务删除设备-地址关系，在设备服务实现层再通过RabBitMQ发送消息到项目服务上删除地址
            PropertyProjectRemoveUnitInfoDTO propertyProjectRemoveUnitInfoDTO = new PropertyProjectRemoveUnitInfoDTO();
            propertyProjectRemoveUnitInfoDTO.setBuildId(buildId);
            iPropertyEquipServiceClient.deleteAddress(propertyProjectRemoveUnitInfoDTO);

            return new MessageVO(buildId,BaseErrorCodeEnum.SUCCESS.getErrorCode());


        } catch (Exception e) {
            throw new DataAccessException("【物业_项目_楼栋信息】删除楼栋信息失败", e);
        }
    }

    /**
     * <desc>
     *      分页查询楼栋信息
     * </desc>
     *
     * @param propertyProjectGetBuildInfoDTO 分页查询楼栋信息数据传输对象
     * @return MessageVO 标准格式化响应结果
     * @author LouisLewis
     * @createDate 2017-09-25
     */
    @RequestMapping(path = "getPage", method = RequestMethod.POST)
    @ResponseBody
    @AuthAccessRequired
    public Object getPage(PropertyProjectGetBuildInfoDTO propertyProjectGetBuildInfoDTO) {
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyProjectGetBuildInfoDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyProjectGetBuildInfoDTO.class, request);
            Page<PropertyProjectBuildInfoVO> page = iPropertyBuildInfoServiceClient.getPage(propertyProjectGetBuildInfoDTO);
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        } catch (Exception e) {
            throw new DataAccessException("【物业_项目_楼栋信息】分页查询楼栋信息失败", e);
        }
        return messageVO;
    }


    /**
     * <desc>
     *      分页查询指定项目下的楼栋简单信息（楼栋id ,楼栋名称）列表
     * </desc>
     *
     * @param propertyProjectGetBuildSimpleInfoDTO 查询楼栋简单信息（楼栋ID，楼栋名称）数据传输对象
     * @return 楼栋简单信息（楼栋id ,楼栋名称）列表
     * @author LewisLouis
     * @createDate 2017-09-28
     */
    @RequestMapping(path = "/getPageSimpleList", method = RequestMethod.POST)
    @ResponseBody
    public Object getPageBuildSimpleInfoList(PropertyProjectGetBuildSimpleInfoDTO propertyProjectGetBuildSimpleInfoDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyProjectGetBuildSimpleInfoDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyProjectGetBuildSimpleInfoDTO.class, request);
            //判断参数合法性
            if (null == propertyProjectGetBuildSimpleInfoDTO) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }

            //项目编号不能为空
            if ((StringUtils.isBlank(propertyProjectGetBuildSimpleInfoDTO.getProjectId()))) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            //分页查询楼栋简单信息列表
            Page<PropertyProjectBuildSimpleInfoVO> page = iPropertyBuildInfoServiceClient.getPageBuildSimpleInfoList(propertyProjectGetBuildSimpleInfoDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);


        } catch (Exception e) {
            throw new DataAccessException("【物业_项目_楼栋信息】分页查询楼栋简单信息列表失败", e);
        }
    }

    /**
     * <desc>
     *      分页查询指定项目下的楼栋简单扩展信息（楼栋id ,楼栋名称,楼栋下房间数量）列表
     * </desc>
     *
     * @param propertyProjectGetBuildSimpleInfoDTO 查询楼栋简单扩展信息（楼栋ID，楼栋名称，楼栋下房间数量）数据传输对象
     * @return MessageVO 标准格式化响应结果（含楼栋简单扩展信息（楼栋ID，楼栋名称，楼栋下房间数量）列表）
     * @author LewisLouis
     * @createDate 2017-11-10
     */
    @RequestMapping(path = "/getPageSimpleListEx", method = RequestMethod.POST)
    @ResponseBody
    public Object getPageBuildSimpleInfoExList(PropertyProjectGetBuildSimpleInfoDTO propertyProjectGetBuildSimpleInfoDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyProjectGetBuildSimpleInfoDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyProjectGetBuildSimpleInfoDTO.class, request);
            //判断参数合法性
            if (null == propertyProjectGetBuildSimpleInfoDTO) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }

            //楼栋编号不能为空
            if ((StringUtils.isBlank(propertyProjectGetBuildSimpleInfoDTO.getProjectId()))) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_BUILD_ID_EMPTY_ERR.getErrorCode());
            }
            //分页查询楼栋简单扩展信息列表
            Page<PropertyProjectBuildSimpleInfoExVO> page = iPropertyBuildInfoServiceClient.getPageBuildSimpleInfoExList(propertyProjectGetBuildSimpleInfoDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);


        } catch (Exception e) {
            throw new DataAccessException("【物业_项目_楼栋信息】分页查询楼栋简单扩展信息列表失败", e);
        }
    }

    /**
     * <desc>
     *      精确查询，获取单个楼栋信息
     * </desc>
     *
     * @param propertyProjectGetBuildInfoDTO 查询楼栋信息数据传输对象
     * @return MessageVO 标准格式化响应结果(含按创建时间降序排列，首个符合查询条件的楼栋信息）
     * @author LouisLewis
     * @createDate 2017-09-25
     */
    @RequestMapping(path = "getOne", method = RequestMethod.POST)
    @ResponseBody
    public Object getOne(PropertyProjectGetBuildInfoDTO propertyProjectGetBuildInfoDTO) {
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyProjectGetBuildInfoDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyProjectGetBuildInfoDTO.class, request);
            if (StringUtils.isNotBlank(propertyProjectGetBuildInfoDTO.getBuildNum())) {
                String buildNum = propertyProjectGetBuildInfoDTO.getBuildNum();
                buildNum = StringHandlerUtil.formatStrLen(buildNum,"0",3,false,false);
                propertyProjectGetBuildInfoDTO.setBuildNum(buildNum);
            }
            PropertyProjectBuildInfoVO propertyProjectBuildInfoVO = iPropertyBuildInfoServiceClient.getOneBuildInfo(propertyProjectGetBuildInfoDTO);
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), propertyProjectBuildInfoVO);
        } catch (Exception e) {
            throw new DataAccessException("【物业_项目_楼栋信息】精确查询单个楼栋信息失败", e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      根据楼栋名称精确查询楼栋信息
     * </desc>
     *
     * @param buildName 楼栋名称
     * @return 楼栋信息
     * @author LewisLouis
     * @createDate 2017-10-17
     */
    private PropertyProjectBuildInfoVO getBuildInfoByBuildName(String buildName, String projectId) {
        PropertyProjectGetBuildInfoDTO propertyProjectGetBuildInfoDTO = new PropertyProjectGetBuildInfoDTO();
        propertyProjectGetBuildInfoDTO.setProjectId(projectId);
        propertyProjectGetBuildInfoDTO.setBuildName(buildName);
        return iPropertyBuildInfoServiceClient.getOneBuildInfo(propertyProjectGetBuildInfoDTO);
    }

    /**
     * <desc>
     *      检查指定楼栋下是否存在房间信息.
     * </desc>
     *
     * @param buildId 楼栋ID
     * @return True：存在    false: 不存在
     * @author LewisLouis
     * @createDate 2017-10-17
     */
    private boolean checkHasRoomInBuild(String buildId) {
        PropertyProjectGetRoomInfoDTO propertyProjectGetRoomInfoDTO = new PropertyProjectGetRoomInfoDTO();
        propertyProjectGetRoomInfoDTO.setBuildId(buildId);
        return null != iPropertyRoomInfoServiceClient.getOneRoomInfo(propertyProjectGetRoomInfoDTO);
    }
}
